#include "CEnemy.h"
#include "MathLib.h"
#include "SGD Wrappers/CSGD_TextureManager.h"
#include "SGD Wrappers/CSGD_Direct3D.h"
#include "CGameplayState.h"
#include "SGD Wrappers/CSGD_DirectInput.h"
#include "VIN_BitMapFont.h"

CBaseEnemy::CBaseEnemy()
{
	m_bAlive = true;
	m_bPassive = true;
	m_vDistanceToPlayer.m_fX = 0.0f;
	m_vDistanceToPlayer.m_fY = 0.0f;
	flip = false;
	SetType(OBJ_ENEMY);
}

CBaseEnemy::~CBaseEnemy()
{

}

void CBaseEnemy::Render()
{
	CSGD_TextureManager* pTM  = CSGD_TextureManager::GetInstance();
	CSGD_Direct3D* d3d  = CSGD_Direct3D::GetInstance();
	RECT tempRECT;

	SetRect(&tempRECT, (int)GetPosX() + GetWidth(), (int)GetPosY() + GetHeight(), (int)GetPosX() + 64, (int)GetPosY() + 128);

	d3d->DrawRect(tempRECT, 255, 0, 0);

	d3d->GetSprite()->Flush();
	if(!m_bPassive)
		VIN_BitMapFont::GetInstance()->Render("ATTACKED", (int)GetPosX(), (int)GetPosY(),1, D3DCOLOR_ARGB(0, 255, 255, 255), 1);
}

void CBaseEnemy::Update( float fElapsedTime)
{
	////m_vDistanceToPlayer.m_fX = GetPosX() - CGamePlayState::GetInstance()->GetPlayer()->GetPosX();
	////m_vDistanceToPlayer.m_fY = GetPosY() - CGamePlayState::GetInstance()->GetPlayer()->GetPosY();
	//
	//if(m_vDistanceToPlayer.LengthOfVector(m_vDistanceToPlayer)  < 70.0f)
	//{
	//	SetVelX(0.0f);
	//	SetVelY(0.0f);
	//
	//	//Attack();
	//}
	//else
	//{
	//	if(GetPosX() > CGamePlayState::GetInstance()->GetPlayer()->GetPosX())
	//	{
	//		SetVelX(-50.0f);
	//	}
	//	else
	//	{
	//		SetVelX(50.0f);
	//		
	//	}
	//	if(GetPosY() > CGamePlayState::GetInstance()->GetPlayer()->GetPosY())
	//	{
	//		SetVelY(-10.0f);
	//	}
	//	else
	//	{
	//		SetVelY(10.0f);
	//	}
	//}



	//SetPosX(GetPosX() + (GetVelX() * fElapsedTime));
	//SetPosY(GetPosY() + (GetVelY() * fElapsedTime));

}
void CBaseEnemy::HandleEvent(CEvent* pEvent)
{
}

void CBaseEnemy::HurtMe(int AmountOfDamageTaken)
{
	SetHP(GetHP() - AmountOfDamageTaken);

	// TODO Stop ALL animation and play the hurt animation and hurt sound
}

void CBaseEnemy::Attack()
{
	CSGD_Direct3D* d3d  = CSGD_Direct3D::GetInstance();
	static float fCooldown = 0.0f;
	// Render Attack Animation after cooldown

	m_bPassive = true;
	if(fCooldown >= 3.0f)
	{
		m_bPassive = false;
		return;
		//fCooldown = 0.0f;
	}

	fCooldown += 0.01f;

}